//
//  CAReturnGoodsListTableViewCell.m
//  LNH
//
//  Created by twentylx on 2018/2/24.
//  Copyright © 2018年 twentylx. All rights reserved.
//

#import "CAReturnGoodsListTableViewCell.h"

@implementation CAReturnGoodsListTableViewCell

- (instancetype) initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (!self) return nil;
    
    [self setBackgroundColor:[UIColor whiteColor]];
    
    [self addSubview:self.headView];
    [self.headView addSubview:self.iconImageView];
    [self.headView addSubview:self.orderNoLabel];
    [self.headView addSubview:self.copyButton];
    [self.headView addSubview:self.orderStatusLabel];
    
    [self addSubview:self.goodsView];
    [self.goodsView addSubview:self.goodsBackgroundView];
    [self.goodsBackgroundView addSubview:self.goodsImageView];
    [self.goodsBackgroundView addSubview:self.goodsNameLabel];
    [self.goodsBackgroundView addSubview:self.sizeLabel];
    [self.goodsBackgroundView addSubview:self.countLabel];
    [self.goodsBackgroundView addSubview:self.lineView];
    [self.goodsView addSubview:self.totalLabel];
    
    [self layoutPageSubviews];
    
    
    return self;
}

#pragma mark getter and setter
- (UIView *) headView {
    if (!_headView) {
        _headView = [UIView new];
        _headView.backgroundColor = RGBCOLOR(247, 247, 247);
    }
    return _headView;
}

- (UIImageView *) iconImageView {
    if (!_iconImageView) {
        _iconImageView = [UIImageView new];
        _iconImageView.image = [UIImage imageNamed:@"orderListIcon"];
    }
    return _iconImageView;
}

- (UILabel *) orderNoLabel {
    if (!_orderNoLabel) {
        _orderNoLabel = [UILabel new];
        _orderNoLabel.textColor = RGBCOLOR(117, 117, 117);
        _orderNoLabel.text = @"订单号：20151212000";
        _orderNoLabel.font = [UIFont systemFontOfSize:14];
    }
    return _orderNoLabel;
}

- (UIButton *) copyButton {
    if (!_copyButton) {
        _copyButton = [UIButton new];
        [_copyButton setTitle:@"复制" forState:UIControlStateNormal];
        [_copyButton setTitleColor:RGBCOLOR(210, 210, 210) forState:UIControlStateNormal];
        _copyButton.titleLabel.font = [UIFont systemFontOfSize:12];
        _copyButton.layer.borderWidth = 1;
        _copyButton.layer.borderColor = [RGBCOLOR(210, 210, 210) CGColor];
        _copyButton.layer.cornerRadius = 2;
    }
    return _copyButton;
}

- (UILabel *) orderStatusLabel {
    if (!_orderStatusLabel) {
        _orderStatusLabel = [UILabel new];
        //        _orderStatusLabel.textColor = RGB(117, 117, 117, 1);
        _orderStatusLabel.text = @"代付款";
        _orderStatusLabel.font = [UIFont systemFontOfSize:14];
        _orderStatusLabel.textAlignment = NSTextAlignmentRight;
        _orderStatusLabel.textColor = RGBCOLOR(235, 109, 52);
        
    }
    return _orderStatusLabel;
}

- (UIView *) goodsView {
    if (!_goodsView) {
        _goodsView = [UIView new];
        _goodsView.backgroundColor = [UIColor clearColor];
        _goodsView.userInteractionEnabled = YES;
    }
    return _goodsView;
}

- (UIView *)goodsBackgroundView {
    if (!_goodsBackgroundView) {
        _goodsBackgroundView = [[UIView alloc] init];
        _goodsBackgroundView.backgroundColor = [UIColor whiteColor];
    }
    return _goodsBackgroundView;
}

- (UIImageView *)goodsImageView {
    if (!_goodsImageView) {
        _goodsImageView = [UIImageView new];
        _goodsImageView.layer.borderWidth = 1;
    }
    return _goodsImageView;
}

- (UILabel *)goodsNameLabel {
    if (!_goodsNameLabel) {
        _goodsNameLabel = [UILabel new];
        _goodsNameLabel.numberOfLines = 3;
        _goodsNameLabel.lineBreakMode = NSLineBreakByCharWrapping;
        _goodsNameLabel.font = [UIFont systemFontOfSize:16];
    }
    return _goodsNameLabel;
}

- (UILabel *)sizeLabel {
    if (!_sizeLabel) {
        _sizeLabel = [UILabel new];
        _sizeLabel.textColor = RGBCOLOR(116, 116, 116);
        _sizeLabel.font = [UIFont systemFontOfSize:14];
        _sizeLabel.numberOfLines = 2;
        _sizeLabel.lineBreakMode = NSLineBreakByCharWrapping;
    }
    return _sizeLabel;
}

- (UILabel *)countLabel {
    if (!_countLabel) {
        _countLabel = [UILabel new];
        _countLabel.textColor = RGBCOLOR(179, 179, 179);
        _countLabel.font = [UIFont systemFontOfSize:16];
        _countLabel.textAlignment = NSTextAlignmentRight;
    }
    return _countLabel;
}

- (UIView *)lineView {
    if (!_lineView) {
        _lineView = [UIView new];
        _lineView.backgroundColor = RGBCOLOR(224, 224, 224);
    }
    return _lineView;
}

- (UILabel *) totalLabel {
    if (!_totalLabel) {
        _totalLabel = [UILabel new];
        _totalLabel.font = [UIFont systemFontOfSize:14];
        _totalLabel.textAlignment = NSTextAlignmentRight;
    }
    return _totalLabel;
}

#pragma mark constraints
- (void) layoutPageSubviews {
    [_headView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.and.right.equalTo(self);
        make.top.equalTo(self);
        make.height.mas_equalTo(44);
    }];
    
    [_iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(15);
        make.centerY.equalTo(self.headView);
    }];
    
    [_orderNoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.iconImageView.mas_right).offset(5);
        make.centerY.equalTo(self.headView);
    }];
    
    [_copyButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.orderNoLabel.mas_right).offset(5);
        make.centerY.equalTo(self.headView);
        make.height.mas_equalTo(12);
    }];
    
    [_orderStatusLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.headView);
        make.right.equalTo(self).offset(-15);
    }];
    
    [_goodsView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.and.right.equalTo(self);
        make.top.equalTo(self.headView.mas_bottom);
        make.bottom.equalTo(self);
    }];
    
    [_goodsBackgroundView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.and.right.equalTo(self.goodsView);
        make.top.equalTo(self.goodsView);
        make.height.mas_equalTo(130);
    }];
    
    [_goodsImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.goodsBackgroundView).offset(10);
        make.top.equalTo(self.goodsBackgroundView).offset(10);
        make.width.mas_equalTo(100);
        make.height.mas_equalTo(100);
    }];
    
    [_goodsNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.goodsImageView.mas_right).offset(10);
        make.top.equalTo(self.goodsImageView).offset(5);
        make.right.equalTo(self.countLabel.mas_left).offset(-5);
    }];
    
    [_sizeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.goodsNameLabel);
        make.top.equalTo(self.goodsNameLabel.mas_bottom).offset(10);
        make.right.equalTo(self.countLabel.mas_left).offset(-5);
    }];
    
    [_countLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.goodsBackgroundView).offset(-20);
        make.centerY.equalTo(self.goodsImageView);
    }];
    
    [_lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.and.right.equalTo(self.goodsBackgroundView);
        make.bottom.equalTo(self.goodsBackgroundView);
        make.height.mas_equalTo(ONE_PIXEL);
    }];
    
    [_totalLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.lineView.mas_bottom).offset(10);
        make.right.equalTo(self.goodsBackgroundView).offset(-20);
    }];
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

@end

